﻿using System;

namespace Utilities.Media.Containers.Ogg
{
    [Flags]
    public enum OggPageHeaderType : byte
    {
        Normal = 0,

        /// <summary>
        /// Defines a continued packet
        /// </summary>
        Continued = 1,

        /// <summary>
        /// Defines the first page of logical bitstream (bos)
        /// </summary>
        Bos = 2,

        /// <summary>
        /// Defines the last page of logical bitstream (eos)
        /// </summary>
        Eos = 4
    }

    public class OggPage
    {
        /// <summary>
        /// The header type flag identifies this page's context in the bitstream
        /// </summary>
        public OggPageHeaderType HeaderType { get; protected set; }

        /// <summary>
        ///  The position specified is the total samples encoded after including all packets finished on this page (packets begun on this page but continuing on to the next page do not count).
        /// </summary>
        public long GranulePosition { get; protected set; }

        /// <summary>
        /// The serial number is the means by which pages physical pages are associated with a particular logical stream. Each logical stream must have a unique serial number within a physical stream.
        /// </summary>
        public int SerialNumber { get; protected set; }

        /// <summary>
        /// Page counter; lets us know if a page is lost (useful where packets span page boundaries).
        /// </summary>
        public int SequenceNumber { get; protected set; }

        /// <summary>
        /// 32 bit CRC value (direct algorithm, initial val and final XOR = 0, generator polynomial=0x04c11db7). The value is computed over the entire header (with the CRC field in the header set to zero) and then continued over the page.
        /// </summary>
        public int Checksum { get; protected set; }

        // Segments

        public OggPage()
        {
            HeaderType = OggPageHeaderType.Normal;
            // capture_patern: "OggS"
            // stream_structure_version: 0x00
            // header_type_flag: 0x??
        }
    }
}
